﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MM.Common.DBBase;
using MM.Common.Base;

namespace MM.Common.Support
{
    public partial class UCCashierInfo : UserControl
    {
        public UCCashierInfo()
        {
            this.InitializeComponent();
        }

        public bool Delete(int empid)
        {
            bool flag = true;
            try
            {
                DataParamCol parms = new DataParamCol(new DataParam[] { new InputDataParam("empid", empid) });
                string commandtext = "DELETE FROM MXHLY_DIC_CASHIER_INFO WHERE EMP_ID = :empid";
                if (SystemInfo.DbData.ExecuteSql(commandtext, parms) < 0)
                {
                    flag = false;
                }
            }
            catch
            {
                flag = false;
            }
            return flag;
        }

        public void DisplayInfo(int empid)
        {
            DataTable dt = new DataTable();
            DataParamCol parm = new DataParamCol(new DataParam[] { new InputDataParam("empid", empid) });
            SystemInfo.DbData.Retrieve("SELECT * FROM MXHLY_DIC_CASHIER_INFO WHERE EMP_ID = :empid", parm, ref dt);
            if (dt.Rows.Count == 1)
            {
                string str = Converts.ConverToString(dt.Rows[0]["REGISTER_INVOICE_NO"], "");
                string str2 = Converts.ConverToString(dt.Rows[0]["OUTP_INVOICE_NO"], "");
                string str3 = Converts.ConverToString(dt.Rows[0]["INP_INVOICE_NO"], "");
                string str4 = Converts.ConverToString(dt.Rows[0]["INP_BILL_NO"], "");
                this.txtRegisterInvoiceNO.Text = str;
                this.txtOutpInvoiceNO.Text = str2;
                this.txtInpInvoiceNO.Text = str3;
                this.txtInpBillNO.Text = str4;
            }
            else
            {
                this.txtRegisterInvoiceNO.Text = "";
                this.txtOutpInvoiceNO.Text = "";
                this.txtInpInvoiceNO.Text = "";
                this.txtInpBillNO.Text = "";
            }
        }

        public void New()
        {
            this.txtRegisterInvoiceNO.Text = "";
            this.txtOutpInvoiceNO.Text = "";
            this.txtInpInvoiceNO.Text = "";
            this.txtInpBillNO.Text = "";
        }

        public bool Save(int empid, bool isexist)
        {
            bool flag = true;
            try
            {
                string text = this.txtRegisterInvoiceNO.Text;
                string paramValue = this.txtOutpInvoiceNO.Text;
                string str3 = this.txtInpInvoiceNO.Text;
                string str4 = this.txtInpBillNO.Text;
                DataParamCol parms = new DataParamCol(new DataParam[] { new InputDataParam("empid", empid) });
                string commandtext = "DELETE FROM MXHLY_DIC_CASHIER_INFO WHERE EMP_ID = :empid";
                if (SystemInfo.DbData.ExecuteSql(commandtext, parms) < 0)
                {
                    SystemInfo.DbData.TransactionRollback();
                    return false;
                }
                if (isexist)
                {
                    commandtext = "INSERT INTO MXHLY_DIC_CASHIER_INFO (EMP_ID ,REGISTER_INVOICE_NO ,OUTP_INVOICE_NO ,INP_INVOICE_NO ,INP_BILL_NO) \r\n   VALUES (:empid ,:register_invoice_no ,:outp_invoice_no ,:inp_invoice_no ,:inp_bill_no) ";
                    parms = new DataParamCol(new DataParam[] { new InputDataParam("empid", empid), new InputDataParam("register_invoice_no", text), new InputDataParam("outp_invoice_no", paramValue), new InputDataParam("inp_invoice_no", str3), new InputDataParam("inp_bill_no", str4) });
                    if (SystemInfo.DbData.ExecuteSql(commandtext, parms, 1) != 1)
                    {
                        SystemInfo.DbData.TransactionRollback();
                        flag = false;
                    }
                }
            }
            catch
            {
            }
            return flag;
        }

        public void SetEnable(bool isedit)
        {
            this.txtRegisterInvoiceNO.Properties.ReadOnly = !isedit;
            this.txtOutpInvoiceNO.Properties.ReadOnly = !isedit;
            this.txtInpInvoiceNO.Properties.ReadOnly = !isedit;
            this.txtInpBillNO.Properties.ReadOnly = !isedit;
        }
    }
}
